package com.sino;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sino.dao.ProductDao;
import com.sino.vo.Product;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * @title: MybatisCRUD
 * @Author Qiulei
 * @Date: 2023/12/4 15:24
 */
@SpringBootTest
public class MybatisCRUD {

    @Autowired
    private ProductDao productDao;


    @Test
    public void specifyFieldSelectTest(){
        LambdaQueryWrapper<Product> queryWrapper = Wrappers.lambdaQuery(Product.class)
                .select(Product::getPcode,Product::getPdName)//指定要查询的字段[可指定多个]
                .eq(Product::getPdId,"1")//查询条件
                .orderByDesc(Product::getPdIndex);//排序
        this.productDao.selectList(queryWrapper);//查询操作
    }

    @Test
    public void specifyFieldUpdatesTest(){
        LambdaUpdateWrapper<Product> updateWrapper =Wrappers.lambdaUpdate(Product.class)
                .set(Product::getPcode,"code1")//更新的字段
                .eq(Product::getPdId,"1");//更新条件

        this.productDao.update(null,updateWrapper);//更新操作
        this.productDao.delete(updateWrapper);//删除操作

    }


}
